package com.jkkc.lib.base.util

import android.os.Bundle
import android.os.Parcelable
import com.alibaba.android.arouter.launcher.ARouter
import com.jkkc.lib.base.extend.PARAMS_BUNDLE
import com.jkkc.lib.base.extend.PARAMS_ITEM
import com.jkkc.lib.base.extend.PARAMS_ROUTER_1
import com.jkkc.lib.base.extend.PARAMS_ROUTER_2
import java.io.Serializable

/**
 * Author:LiXian
 * <p>
 * Desc:ARouter
 * Version:1.0
 * date 2022/10/12 13:54
 */
object ARouterUtils {

    /**
     * 跳转页面（不带参数）
     *
     * @param path activity地址
     */
    fun navigation(path: String) {
        if (path.isNotEmpty()) {
            ARouter.getInstance().build(path).navigation()
        }
    }

    fun navigation(path: String, param: String) {
        if (path.isNotEmpty()) {
            ARouter.getInstance().build(path).withString(PARAMS_ROUTER_1, param).navigation()
        }
    }

    fun navigation(path: String, param: Boolean) {
        if (path.isNotEmpty()) {
            ARouter.getInstance().build(path).withBoolean(PARAMS_ROUTER_1, param).navigation()
        }
    }

    fun navigation(path: String, param1: String, param2: String) {
        if (path.isNotEmpty()) {
            ARouter.getInstance().build(path)
                .withString(PARAMS_ROUTER_1, param1)
                .withString(PARAMS_ROUTER_2, param2)
                .navigation()
        }
    }

    fun navigation(path: String, bundle: Bundle) {
        if (path.isNotEmpty()) {
            ARouter.getInstance()
                .build(path)
                .withBundle(PARAMS_BUNDLE, bundle)
                .navigation()
        }
    }

    fun <T : Parcelable> navigation(path: String, item: T) {
        if (path.isNotEmpty()) {
            ARouter.getInstance()
                .build(path)
                .withParcelable(PARAMS_ITEM, item)
                .navigation()
        }
    }

    fun <T : Serializable> navigation(path: String, item: T) {
        if (path.isNotEmpty()) {
            ARouter.getInstance()
                .build(path)
                .withSerializable(PARAMS_ITEM, item)
                .navigation()
        }
    }
}